package org.kingtop.mybatis.mapper;

import org.kingtop.mybatis.plugin.Pagination;
import org.kingtop.service.IBaseService;
import org.kingtop.sys.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 基础服务的实现
 *
 * @author 陈金波
 * @date 2018年1月4日 下午5:09:29
 * @Copyright: 2018 kingtop.
 */
public class BaseServiceImpl<T> implements IBaseService<T> {

    protected Logger log = LoggerFactory.getLogger(getClass());

    private IBaseDaoMapper<T> baseDao;

    @Autowired(required = false)
    public void setBaseDao(IBaseDaoMapper<T> baseDao) {
        this.baseDao = baseDao;
    }

    @Override
    public T getById(Long id) {
        return this.baseDao.getById(id);
    }

    @Override
    public List<T> listByIds(List<Long> ids) {
        return this.baseDao.listByIds(ids);
    }

    @Override
    public List<T> listByBean(T value) {
        return this.baseDao.listByBean(value);
    }

    @Override
    public int add(T value) {
        return this.baseDao.add(value);
    }

    @Override
    public int update(T value) {
        return this.baseDao.update(value);
    }

    @Override
    public int updateForNotNull(T value) {
        return this.baseDao.updateForNotNull(value);
    }

    @Override
    public List<T> listAll() {
        return this.baseDao.listAll();
    }

    @Override
    public PageBean<T> pageByBean(T value, int pageIndex, int pageSize) {
        return this.baseDao.pageByBean(value, Pagination.of(pageIndex, pageSize));
    }

    @Override
    public int deleteById(Long id) {
        return this.baseDao.deleteById(id);
    }

    @Override
    public int deleteByIds(List<Long> ids) {
        return this.baseDao.deleteByIds(ids);
    }

    @Override
    public int deleteByBean(T value) {
        return this.baseDao.deleteByBean(value);
    }

}
